<?php

/**
 * This is the model class for table "invcompany".
 *
 * The followings are the available columns in table 'invcompany':
 * @property string $companyid
 * @property string $companyname
 * @property string $aliasname
 * @property integer $appcompanygroupid
 * @property boolean $isappcompany
 * @property string $companysuperparentid
 * @property string $companyparentid
 * @property string $address
 * @property string $addresslocationid
 * @property string $taxid
 * @property boolean $isactive
 * @property string $createdby
 * @property string $createdon
 * @property string $lastupdateby
 * @property string $lastupdateon
 *
 * The followings are the available model relations:
 * @property Invcompanybranch[] $invcompanybranches
 * @property Cctvcamera[] $cctvcameras
 * @property Invcompanybranch[] $invcompanybranches1
 * @property Masterappcompanygroup $appcompanygroup
 * @property Gflocation $addresslocation
 * @property Sysappmenugroup[] $sysappmenugroups
 */
class Invcompany extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'invcompany';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('companyid, companyname, aliasname, createdby, createdon', 'required'),
			array('appcompanygroupid', 'numerical', 'integerOnly'=>true),
			array('companyname, aliasname, createdby, lastupdateby', 'length', 'max'=>100),
			array('address, taxid', 'length', 'max'=>50),
			array('isappcompany, companysuperparentid, companyparentid, addresslocationid, isactive, lastupdateon', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('companyid, companyname, aliasname, appcompanygroupid, isappcompany, companysuperparentid, companyparentid, address, addresslocationid, taxid, isactive, createdby, createdon, lastupdateby, lastupdateon', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'invcompanybranches' => array(self::MANY_MANY, 'Invcompanybranch', 'cctvcamerasetting(companyid, companybranchid)'),
			'cctvcameras' => array(self::HAS_MANY, 'Cctvcamera', 'companyid'),
			'invcompanybranches1' => array(self::HAS_MANY, 'Invcompanybranch', 'companyid'),
			'appcompanygroup' => array(self::BELONGS_TO, 'Masterappcompanygroup', 'appcompanygroupid'),
			'addresslocation' => array(self::BELONGS_TO, 'Gflocation', 'addresslocationid'),
			'sysappmenugroups' => array(self::HAS_MANY, 'Sysappmenugroup', 'companyid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'companyid' => 'Companyid',
			'companyname' => 'Companyname',
			'aliasname' => 'Aliasname',
			'appcompanygroupid' => 'Appcompanygroupid',
			'isappcompany' => 'Isappcompany',
			'companysuperparentid' => 'Companysuperparentid',
			'companyparentid' => 'Companyparentid',
			'address' => 'Address',
			'addresslocationid' => 'Addresslocationid',
			'taxid' => 'Taxid',
			'isactive' => 'Isactive',
			'createdby' => 'Createdby',
			'createdon' => 'Createdon',
			'lastupdateby' => 'Lastupdateby',
			'lastupdateon' => 'Lastupdateon',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('companyid',$this->companyid,true);
		$criteria->compare('companyname',$this->companyname,true);
		$criteria->compare('aliasname',$this->aliasname,true);
		$criteria->compare('appcompanygroupid',$this->appcompanygroupid);
		$criteria->compare('isappcompany',$this->isappcompany);
		$criteria->compare('companysuperparentid',$this->companysuperparentid,true);
		$criteria->compare('companyparentid',$this->companyparentid,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('addresslocationid',$this->addresslocationid,true);
		$criteria->compare('taxid',$this->taxid,true);
		$criteria->compare('isactive',$this->isactive);
		$criteria->compare('createdby',$this->createdby,true);
		$criteria->compare('createdon',$this->createdon,true);
		$criteria->compare('lastupdateby',$this->lastupdateby,true);
		$criteria->compare('lastupdateon',$this->lastupdateon,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Invcompany the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
